<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/4/8
  Time: 11:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="<%=request.getContextPath()%>/css/font.css">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/css/xadmin.css">
    <script src="<%=request.getContextPath()%>/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/xadmin.js"></script>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">

        <form class="layui-form">
            <div class="layui-form-item">
                <label for="productNum" class="layui-form-label">
                    产品编号
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="productNum" name="productNum" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="productName" class="layui-form-label">
                    产品名称
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="productName" name="productName" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="cityName" class="layui-form-label">
                    出发城市
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="cityName" name="cityName" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="departureTime" class="layui-form-label">
                    出发时间
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="departureTime" name="departureTime" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="productPrice" class="layui-form-label">
                    产品价格
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="productPrice" name="productPrice" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="productPrice" class="layui-form-label">
                    产品描述
                </label>
                <div class="layui-input-inline">
                    <textarea name="productDesc" id="productDesc" style="min-width: 100px;min-height: 50px;max-width: 100px;"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">产品状态</label>
                <div class="layui-input-block">
                    <input type="radio" name="productStatus" value="0" title="关闭">
                    <input type="radio" name="productStatus" value="1" title="开启" checked>
                </div>
            </div>
            <div class="layui-form-item">
                <button  class="layui-btn" lay-filter="add" lay-submit="">
                    增加
                </button>
            </div>
        </form>
    </div>
</div>
<script>layui.use(['form', 'layer','laydate'],
    function() {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer
        ,laydate = layui.laydate;

        laydate.render({
            elem:"#departureTime",
            type:"date"
        })

        //自定义验证规则
        form.verify({
            nikename: function(value) {
                if (value.length < 5) {
                    return '昵称至少得5个字符啊';
                }
            },
            pass: [/(.+){6,12}$/, '密码必须6到12位'],
            repass: function(value) {
                if ($('#L_pass').val() != $('#L_repass').val()) {
                    return '两次密码不一致';
                }
            }
        });

        //监听提交
        form.on('submit(add)',
            function(data) {
                // console.log(data);
                //获取表单中的数据
                let formData = data.field;
                $.ajax({
                    url:"/mv/product/insert",
                    type:"post",
                    contentType:"application/json;charset=utf-8",
                    data:JSON.stringify(formData),
                    success:function(res){
                        console.log(res);
                    }
                })
                layer.alert("增加成功", {
                        icon: 6
                    },
                    function() {
                        //关闭当前frame
                        xadmin.close();

                        // 可以对父窗口进行刷新
                        xadmin.father_reload();
                    });
                return false;
            });

    });</script>
</body>

</html>
